home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_02 / 9n02124a < prev    next >
Text File  |  1990-12-15  |  1KB  |  73 lines

  1.  
  2.  
  3.  
  4. /*** IN THE FILE GLOBALS.H ***/
  5.  
  6. #ifdef ALLOCATE_SPACE /* allocate space for globals */
  7. #define GLOBAL
  8. #define INIT(x)  x
  9. #else                 /* just declare externals */
  10. #define GLOBAL   extern
  11. #defint INIT(x)
  12. #endif
  13.  
  14. /*
  15. NOTE:  The INIT(x) macro won't work with aggregates
  16. because it interprets a comma as indicating a new
  17. macro parameter, not as part of the current
  18. parameter.  Aggregates are initialized with 
  19. #ifdef ALLOCATE_SPACE
  20. */
  21.  
  22. GLOBAL
  23. int  variable1 INIT(=1),
  24.      variable2;
  25.  
  26. GLOBAL
  27. int  variable1 INIT(=1),
  28.      variable2;
  29.  
  30. GLOBAL
  31. struct range 
  32.      {
  33.      int xmin, xmax, ymin, ymax;
  34.      } data_range
  35. #ifdef ALLOCATE_SPACE
  36.      = { 0, 0, 0, 0, 0 }
  37. #endif
  38. ;
  39.  
  40. /**   IN THE MAIN .C FILE    ***/
  41.  
  42. #define ALLOCATE_SPACE
  43. #include  "globals.h"
  44.  
  45. /* So, our inclusion becomes: */
  46.  
  47. int  variable1 = 1,
  48.      variable2;
  49.  
  50. struct range 
  51.      {
  52.      int xmin, xmax,; ymin, ymax;
  53.      } data_range = { 0, 0, 0, 0 };
  54.  
  55. /* IN ALL OTHER .C FILES */
  56.  
  57. #include "globals.h"
  58.  
  59. /*  So our inclusion becomes: */
  60.  
  61. extern
  62. int variable1,
  63.     variable2;
  64.  
  65. extern
  66. struct range 
  67.      {
  68.      int xmin, xmax, ymin, ymax;
  69.      } data_range;
  70.  
  71.  
  72.  
  73.